//
//  MainTopView.m
//  CBT
//
//  Created by 四点钟 on 2018/11/16.
//  Copyright © 2018 Mr.Zhang. All rights reserved.
//

#import "MainTopView.h"

@interface MainTopView()

@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIImageView *topLeftImageView;
@property (nonatomic, strong) UIButton *topMoreBtn;

@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIImageView *bottomRootImageView;
@property (nonatomic, strong) UILabel *bottomLeftLabel;
@property (nonatomic, strong) UILabel *totalLIncomeLabel;
@property (nonatomic, strong) UIView *bottomLineView;

//@property (nonatomic, strong) UIView *sectionView;
//@property (nonatomic, strong) UIImageView *sectionIconImageView;
//@property (nonatomic, strong) UIButton *sectionRightBtn;
@end

@implementation MainTopView

- (void)initSubViews
{
    self.backgroundColor = [UIColor clearColor];
    
    __weak typeof(self) weakSelf = self;
    
    _rootImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenNarrowSide, 150)];
    _rootImageView.image = [UIImage imageNamed:@"wode_beijing"];
    [self addSubview:_rootImageView];
    
    _topView = [[UIView alloc]init];
    _topView.backgroundColor     = [UIColor whiteColor];
    _topView.layer.cornerRadius  = 5;
    _topView.layer.masksToBounds = YES;
    [self addSubview:_topView];
    
    _topLeftImageView = [[UIImageView alloc]init];
    _topLeftImageView.image = [UIImage imageNamed:@"shouye_tongzhi"];
    [_topView addSubview:_topLeftImageView];
    
    _topMoreBtn = [[UIButton alloc]init];
    [_topMoreBtn setTitleColor:UIColorFromRGB(0x333333) forState:(UIControlStateNormal)];
    _topMoreBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [_topView addSubview:_topMoreBtn];
    [_topMoreBtn addTarget:self action:@selector(topMoreBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    _rollView = [[HFFanClubJoinRollView alloc]init];
    [_rollView setNewsTextColor:UIColorFromRGB(0x333333)];
    [_rollView setRollViewBlock:^(NSInteger index) {
        if (weakSelf.MainTopViewBlock != nil) {
            weakSelf.MainTopViewBlock(1, index);
        }
    }];
    [_topView addSubview:_rollView];
    
    _bottomView = [[UIView alloc]init];
    _bottomView.backgroundColor = [UIColor clearColor];
    [self addSubview:_bottomView];
    
    _bottomRootImageView = [[UIImageView alloc]init];
    _bottomRootImageView.image = [UIImage imageNamed:@"shouye_new_zhanshiban_ditu"];
    [_bottomView addSubview:_bottomRootImageView];
    _bottomRootImageView.userInteractionEnabled = YES;
    
    _bottomLeftLabel = [[UILabel alloc]init];
    _bottomLeftLabel.font = [UIFont systemFontOfSize:16];
    _bottomLeftLabel.textAlignment = NSTextAlignmentCenter;
    _bottomLeftLabel.textColor = UIColorFromRGB(0x333333);
    [_bottomView addSubview:_bottomLeftLabel];
    
    _bottomLineView = [[UIView alloc]init];
    _bottomLineView.backgroundColor = LineViewBgColor;
    [_bottomView addSubview:_bottomLineView];
    
    _totalLIncomeLabel = [[UILabel alloc]init];
    _totalLIncomeLabel.font = [UIFont systemFontOfSize:16];
    _totalLIncomeLabel.textAlignment = NSTextAlignmentCenter;
    _totalLIncomeLabel.textColor = UIColorFromRGB(0x333333);
    [_bottomView addSubview:_totalLIncomeLabel];
    
    _yesterdayEaLabel = [[UILabel alloc]init];
    _yesterdayEaLabel.font = [UIFont systemFontOfSize:15];
    _yesterdayEaLabel.textAlignment = NSTextAlignmentCenter;
    _yesterdayEaLabel.textColor = UIColorFromRGB(0x526DF9);
    _yesterdayEaLabel.text = @"0";
    [_bottomView addSubview:_yesterdayEaLabel];
    
    
    _totalLIncomeCount = [[UILabel alloc]init];
    _totalLIncomeCount.font = [UIFont systemFontOfSize:15];
    _totalLIncomeCount.textAlignment = NSTextAlignmentCenter;
    _totalLIncomeCount.text = @"0";
    _totalLIncomeCount.textColor = UIColorFromRGB(0x526DF9);
    [_bottomView addSubview:_totalLIncomeCount];
    
    [self detaultInfo];
}

- (void)pushAction:(UIButton *)btn
{
    if (self.MainTopViewBlock != nil) {
        self.MainTopViewBlock(2, 0);
    }
}

- (void)topMoreBtnAction:(UIButton *)btn
{
    if (self.MainTopViewBlock != nil) {
        self.MainTopViewBlock(0, 0);
    }
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(34);
    }];
    
    [_topLeftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(17);
        make.width.mas_equalTo(14);
        make.height.mas_equalTo(17);
        make.top.mas_offset(8);
    }];

    [_topMoreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.width.mas_equalTo(54);
        make.top.bottom.mas_equalTo(0);
    }];

    [_rollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.topLeftImageView.mas_right).offset(10);
        make.right.mas_equalTo(weakSelf.topMoreBtn.mas_left);
        make.top.bottom.mas_equalTo(0);
    }];
    
    [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(self.topView.mas_bottom).offset(6);
        make.height.mas_equalTo(110);
    }];

    [_bottomRootImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    
    [_bottomLeftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(29);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(self.bottomView).multipliedBy(0.5);
    }];
    
    [_bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(70);
        make.top.mas_equalTo(20);
        make.left.mas_equalTo(self.bottomLeftLabel.mas_right);
    }];
    
    [_totalLIncomeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.bottomLeftLabel.mas_right);
        make.top.mas_equalTo(29);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(self.bottomView).multipliedBy(0.5);
    }];
    
    [_yesterdayEaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(self.bottomLeftLabel.mas_bottom).offset(24);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(self.bottomView).multipliedBy(0.5);
    }];
    
    [_totalLIncomeCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.yesterdayEaLabel.mas_right);
        make.top.mas_equalTo(self.bottomLeftLabel.mas_bottom).offset(24);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(self.bottomView).multipliedBy(0.5);
    }];
}

- (void)detaultInfo
{
    [_topMoreBtn setTitle:kLocalizedString(@"更多", nil) forState:(UIControlStateNormal)];
    _bottomLeftLabel.text   = kLocalizedString(@"昨日收益（PC）", nil);
    _totalLIncomeLabel.text = kLocalizedString(@"总计收益（PC）", nil);
}

- (void)changeLanguage {
    [self detaultInfo];
}


@end
